/**
 * @file ai_terminal.h
 * @brief Local terminal communication for AI interaction
 */

#ifndef AI_TERMINAL_H
#define AI_TERMINAL_H

#include "stlstrings.h"
#include <vector>
#include <map>
#include <wx/process.h>
#include <wx/txtstrm.h>

class AITerminal : public wxProcess
{
public:
    AITerminal();
    
    bool StartTerminal(const wxString& shell = "cmd.exe");
    wxString ExecuteCommand(const wxString& command, int timeout_ms = 30000);
    std::vector<wxString> ExecuteCommands(const std::vector<wxString>& commands, int timeout_ms = 30000);
    wxString ExecuteScript(const wxString& scriptPath, const wxString& interpreter = "");
    bool ExecuteInteractive(const wxString& command);
    wxString GetLastOutput() const { return m_lastOutput; }
    wxString GetLastError() const { return m_lastError; }
    bool IsRunning() const;
    void StopTerminal();

private:
    wxProcess* m_process;
    wxInputStream* m_inputStream;
    wxOutputStream* m_outputStream;
    wxString m_lastOutput;
    wxString m_lastError;
    bool m_isRunning;
    
    wxString ReadOutput(int timeout_ms = 5000);
    bool WriteCommand(const wxString& command);
    void OnTerminate(int pid, int status) override;
};

#endif
